using UnityEngine;

public class ButtonPositionLoader : MonoBehaviour
{
	public string keyButton;

	public bool right;

	public UIWidget leftButtonsWidget;

	public UIWidget rightButtonsWidget;

	private Vector3 pos = Vector3.zero;

	public void OnEnable()
	{
		if (PlayerPrefs.HasKey(ButtonPositionSaver.key + keyButton))
		{
			ButtonPositionInfo parent = new ButtonPositionInfo(PlayerPrefs.GetString(ButtonPositionSaver.key + keyButton));
			SetScale(parent.param[2]);
			SetParent(parent);
		}
		else if (keyButton == "zatichka")
		{
			Vector3 vector = default(Vector3);
			vector = base.transform.localPosition;
			vector.x = Mathf.Abs(base.transform.localPosition.x);
			pos = vector;
			SetParent();
		}
	}

	private void SetScale(float value)
	{
		base.transform.localScale = new Vector3(0.5f + value, 0.5f + value, 1f);
	}

	private void SetPosition(float x, float y)
	{
		bool flag = (!settings.LeftHandControlEnable && right) || (!right && settings.LeftHandControlEnable);
		base.transform.localPosition = new Vector3(x * ((!flag) ? 1f : (-1f)), y, 0f);
	}

	private void SetParent(ButtonPositionInfo info)
	{
		if ((!settings.LeftHandControlEnable && right) || (settings.LeftHandControlEnable && !right))
		{
			if ((bool)rightButtonsWidget)
			{
				base.transform.SetParent(rightButtonsWidget.transform);
				base.transform.localPosition = new Vector3(0f - info.param[0], info.param[1], 0f);
			}
		}
		else if ((bool)leftButtonsWidget)
		{
			base.transform.SetParent(leftButtonsWidget.transform);
			base.transform.localPosition = new Vector3(info.param[0], info.param[1], 0f);
		}
	}

	private void SetParent()
	{
		if ((!settings.LeftHandControlEnable && right) || (settings.LeftHandControlEnable && !right))
		{
			if ((bool)rightButtonsWidget)
			{
				base.transform.SetParent(rightButtonsWidget.transform);
				base.transform.localPosition = new Vector3(0f - pos.x, pos.y, 0f);
			}
		}
		else if ((bool)leftButtonsWidget)
		{
			base.transform.SetParent(leftButtonsWidget.transform);
			base.transform.localPosition = new Vector3(pos.x, pos.y, 0f);
		}
	}
}
